﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PFAGame
{
    class NewStoryGameMenuScreen : MenuScreen
    {
        #region Fields

        MenuEntry difficultiGameMenuEntry;
        MenuEntry characterGameMenuEntry;

        static string[] dificulties = { "Easy", "Medium", "Hard" };
        static int currentDificulties = 0;

        static string[] character = { "Frank", "Suzie" };
        static int currentCharacter = 0;

        #endregion

        #region Initialization

        public NewStoryGameMenuScreen()
            : base("New Story")
        {
            // Create our menu entries.
            difficultiGameMenuEntry = new MenuEntry(string.Empty);
            characterGameMenuEntry = new MenuEntry(string.Empty);
            MenuEntry playMenuEntry = new MenuEntry("Play");
            MenuEntry backMenuEntry = new MenuEntry("Back");

            SetMenuEntryText();

            // Hook up menu event handlers.
            difficultiGameMenuEntry.Selected += DifficultiesChoice;
            characterGameMenuEntry.Selected += CharacterChoice;
            playMenuEntry.Selected += OnPlay;
            backMenuEntry.Selected += OnCancel;

            // Add entries to the menu.
            MenuEntries.Add(difficultiGameMenuEntry);
            MenuEntries.Add(characterGameMenuEntry);
            MenuEntries.Add(playMenuEntry);
            MenuEntries.Add(backMenuEntry);
        }

        void SetMenuEntryText()
        {
            difficultiGameMenuEntry.Text = "Difficulty : " + dificulties[currentDificulties];
            characterGameMenuEntry.Text = "Character : " + character[currentCharacter];
        }

        #endregion

        #region Handle Input

        void OnPlay(object sender, PlayerIndexEventArgs e)
        {
            e_class playerClass = currentCharacter == 0 ? e_class.BOURRIN : e_class.SPECIALISTE;
            LoadingScreen.Load(ScreenManager.Singleton, true, e.PlayerIndex, new GameplayScreen(null, playerClass, e_GameMode.STORY, currentDificulties, -1));
        }

        void DifficultiesChoice(object sender, PlayerIndexEventArgs e)
        {
            currentDificulties = (currentDificulties + 1) % dificulties.Length;

            SetMenuEntryText();
        }

        void CharacterChoice(object sender, PlayerIndexEventArgs e)
        {
            currentCharacter = (currentCharacter + 1) % character.Length;

            SetMenuEntryText();
        }

        new protected void OnCancel(object sender, PlayerIndexEventArgs e)
        {
            ScreenManager.Singleton.AddScreen(new StoryMenuScreen(), e.PlayerIndex);
        }

        #endregion
    }
}
